package sun.management.counter.perf;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import sun.management.counter.Counter;
import sun.management.counter.perf.PerfInstrumentation;
import sun.misc.Perf;

@SuppressWarnings("restriction")
public class PerfData {
	
	public static void main(String args[]) throws IOException{
		PerfData pd = new PerfData(5809);
	}

	public PerfData(int pid) throws IOException {
		// Attach to the instrumentation buffer for the specified Java virtual machine
		ByteBuffer bb = Perf.getPerf().attach(pid, "r");
		PerfInstrumentation instr = new PerfInstrumentation(bb);
		
		Map<String, Counter> result = new HashMap<>(512);
		for (Counter c : instr.getAllCounters()) {
			result.put(c.getName(), c);
		}
		
		for(Entry<String, Counter> m:result.entrySet()){
			System.out.println(m.getKey() + " ---  "+ m.getValue());
		}
	}
}
